package com.xieyong.leetcode;

public class Leetcode2138 {
    public static void main(String[] args) {
        Leetcode2138 leetcode2138 = new Leetcode2138();
        String s = "abcdefghiasdf";
        int k = 3;
        char fill = 'x';
        String[] strings = leetcode2138.divideString(s, k, fill);
        for (String string : strings) {
            System.out.println(string);
        }
    }


    public String[] divideString(String s, int k, char fill) {
        int n = s.length() / k;
        int m = s.length() % k;
        String[] res = new String[m == 0 ? n : n + 1];
        int index = 0;
        for (int i = 0; i < n; i++ , index += k) {
            res[i] = s.substring(index, index + k);
        }
        if (m > 0) {
            StringBuffer sbuf = new StringBuffer();
            sbuf.append(s.substring(index));
            for (int i = 0; i < k - m; i++) {
                sbuf.append(fill);
            }
            res[n] = sbuf.toString();
        }
        return res;
    }
}
